package com.lyx.question.controller;

import com.lyx.common.result.R;
import com.lyx.common.utils.JwtUtils;
import com.lyx.question.dto.PaperResultDto;
import com.lyx.question.dto.PaperWitnQuestionDto;
import com.lyx.question.dto.QuestionDto;
import com.lyx.question.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 试卷
 * @author 14667
 * @date 2022/7/26 10:39
 */
@RestController
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    PaperService paperService;

    /**
     * 章节内生成试卷
     * @param httpServletRequest
     * @param chapterId
     * @return
     */
    @GetMapping("/generatePaperByChapter")
    public R generatePaper(HttpServletRequest httpServletRequest, @RequestParam Integer chapterId){

        PaperWitnQuestionDto data = paperService.generatePaperByChapter(httpServletRequest,chapterId);
        return R.ok().data("data",data);
    }

    /**
     * 随机生成试卷
     * @param httpServletRequest
     * @param chapterId
     * @return
     */
    @GetMapping("/randomGeneratePaper")
    public R randomGeneratePaper(HttpServletRequest httpServletRequest,@RequestParam Integer chapterId){
        PaperWitnQuestionDto data = paperService.randomGeneratePaper(httpServletRequest,chapterId);

        return R.ok().data("data",data);
    }

    /**
     * 交卷
     * @param paperWitnQuestionDto
     * @param request
     * @return
     */
    @PostMapping("/submitPaper")
    public R submitPaper(@RequestBody PaperWitnQuestionDto paperWitnQuestionDto,HttpServletRequest request){
        paperService.submitPaper(paperWitnQuestionDto,request);
        return R.ok().message("交卷成功");
    }

    /**
     * 获取批改结果
     * @param paperId
     * @param request
     * @return
     */
    @GetMapping("/getPaperResult")
    public R getPaperResult(@RequestParam Integer paperId,HttpServletRequest request){
        PaperResultDto data = paperService.getPaperResult(paperId,request);
        return R.ok().data("data",data).message("获取批改结果成功");
    }


}
